home *** CD-ROM | disk | FTP | other *** search
- /*================================================================================
- StringUtilities.h
-
- ©1991 Greg Anderson
- greggor@apple.com
-
- FREE DISTRIBUTION
-
- The possessor of this source code may use any portion of
- it for any purpose, and I place no restriction on its
- redistribution.
-
- This .h file provides macros for scanning through strings.
- It is assumed that all strings being scanned are null-terminated
-
- ================================================================================*/
- #ifndef __STRINGUTILITIES__
- #define __STRINGUTILITIES__
-
- #ifndef __TYPES__
- #include <Types.h>
- #endif
-
- #define IsDigit(c) ( ((c) >= '0') && ((c) <= '9') )
- #define IsNumeric(c) ( IsDigit(c) || ((c) == '-') )
- #define IsAlpha(c) ( ( ((c) >= 'A') && ((c) <= 'Z') ) || ( ((c) >= 'a') && ((c) <= 'z') ) )
- #define IsAlphaNumeric(c) ( IsNumeric(c) || IsAlpha(c) )
- #define IsWhiteSpace(c) ( (c) <= ' ' )
-
- /*
- // Macros:
- //
- // ToUpper(c)
- //
- // Convert 'c' to an uppercase character if it is a lowercase character
- //
- // SkipToWhiteSpace(p)
- //
- // Skip to the next whitespace character (or null)
- //
- // SkipPastWhitespace(p)
- //
- // Skip to the next non-whitespace character (or null)
- //
- // SkipToSpec(p,spec)
- //
- // Skip to the next occurance of the specified character (or null)
- //
- // SkipToDigit(p)
- //
- // Skip to the next numeric digit (or null)
- //
- // SkipToNextLine(p)
- //
- // Like it says: skip to the beginning of the next line
- */
- #define ToUpper(c) ( ((c >= 'a') && (c <= 'z')) ? c - 'a' + 'A' : c )
- #define SkipToWhitespace( line ) while( *(line) > ' ' ) (line)++
- #define SkipPastWhitespace( line ) while( (*(line) <= ' ') && (*(line) != '\r') && (*(line)) ) (line)++
- #define SkipToSpec( line, spec ) while( (*(line) != spec) && (*(line)) ) (line)++
- #define SkipToDigit( line ) while( ((*(line) < '0') || (*(line) > '9')) && (*(line)) ) (line)++
- #define SkipToNextLine( line ) do{ SkipToSpec(line, '\r'); while( (*(line) < ' ') && (*(line)) ) (line)++; } while(false)
-
- /*
- // Prototypes for stringUtilities.c
- */
- void PtoCcpy( char* cstr, Str255 pstr );
- void CtoPcpy( Str255 pstr, char* cstr );
- short PtoCcmp( Str255 pstr, char* cstr );
- pascal void pstrcpy( Str255 dest, Str255 src );
- pascal void pstrcat( Str255 dest, Str255 src );
- short pstrcmp( unsigned char* a, unsigned char* b );
- short partialstrcmp( register char* s1, register char* s2);
- short ScanNumberInString( char** line );
- short NumberInString( char* line );
- void ScanTextInString( char** line, Str255 pstr, Boolean terminateAtSpace );
- void ScanWordInString( char** line, Str255 pstr );
- void ScanLineInString( char** line, Str255 pstr );
-
- void AddHexCharToString( char* where, unsigned short hexNumber );
- void AddHexByteToString( char* where, unsigned short hexNumber );
- void AddHexShortToString( char* where, unsigned short hexNumber );
- void AddHexLongToString( char* where, unsigned long hexNumber );
-
- #endif
-